package es.upv.tricia;

import java.util.HashSet;

public class QuestionCategorySet extends HashSet<QuestionCategory>
{
	/**
	 * Generated automatically by eclipse
	 */
	private static final long serialVersionUID = 4931753833194433190L;

	public static QuestionCategorySet unserialize(String string)
	{
		QuestionCategorySet set = new QuestionCategorySet();

		String[] parts = string.split(",");

		for (int i = 0; i < parts.length; ++i) {
			try {
				if (parts[i].length() > 0) {
					set.add(QuestionCategory.valueOf(parts[i]));
				}
			} catch (IllegalArgumentException e) {
				// graceful failure to ensure BC
			}
		}

		return set;
	}

	public String serialize()
	{
		StringBuilder builder = new StringBuilder();
		boolean first = true;

		for (QuestionCategory pref : this) {
			if (!first) {
				builder.append(',');
			}

			builder.append(pref.name());
			first = false;
		}

		return builder.toString();
	}
}
